package com.arturjaneczko.view.impl.clipboard.preview._cell;

import java.awt.Component;

import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

import com.arturjaneczko.model.impl.EClipboardDataType;
import com.arturjaneczko.view.impl.clipboard._component.ClipboardObjectTypeView;
import com.arturjaneczko.view.impl.clipboard._component.Color;

@SuppressWarnings("serial")
public class TypeCell extends AbstractCellEditor implements TableCellEditor,
		TableCellRenderer {

	private ClipboardObjectTypeView clipboardObjectTypeView;
	private CellModel cellModel;

	public TypeCell(CellModel cellModel) {
		super();
		clipboardObjectTypeView = new ClipboardObjectTypeView();
		this.cellModel = cellModel;
	}

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		java.awt.Color color;
		if (row == cellModel.getRow()) {
			color = Color.NOTE_SELECTED.getColor();
		} else {
			color = Color.NOTE.getColor();
		}
		EClipboardDataType clipboardDataType = (EClipboardDataType) value;
		update(clipboardDataType, color);
		return clipboardObjectTypeView;
	}

	@Override
	public Component getTableCellEditorComponent(JTable table, Object value,
			boolean isSelected, int row, int column) {
		return clipboardObjectTypeView;
	}

	@Override
	public Object getCellEditorValue() {
		return null;
	}
	
	private void update(EClipboardDataType clipboardDataType,
			java.awt.Color color) {
		clipboardObjectTypeView.update(clipboardDataType, color);
	}

}